﻿using System;
using System.Globalization;
using System.Reflection;
using Aliyun.MNS.Util;

namespace Aliyun.MNS.Runtime.Internal.Util
{
    /// <summary>
    /// Logger wrapper for reflected log4net logging methods.
    /// </summary>
    internal class InternalLog4NetLogger : InternalLogger
    {
        private log4net.ILog internalLogger;

        public InternalLog4NetLogger(Type declaringType)
            : base(declaringType)
        {
            this.internalLogger = log4net.LogManager.GetLogger(declaringType.Assembly, declaringType);
        }

        #region Overrides

        public override void Flush()
        {
        }

        /// <summary>
        /// Simple wrapper around the log4net IsErrorEnabled property.
        /// </summary>
        public override bool IsErrorEnabled
        {
            get
            {
                return this.internalLogger.IsErrorEnabled;
            }
        }

        /// <summary>
        /// Simple wrapper around the log4net Error method.
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="messageFormat"></param>
        /// <param name="args"></param>
        public override void Error(Exception exception, string message)
        {
            this.internalLogger.Error(message, exception);
        }

        /// <summary>
        /// Simple wrapper around the log4net IsDebugEnabled property.
        /// </summary>
        public override bool IsDebugEnabled
        {
            get
            {
                return this.internalLogger.IsDebugEnabled;
            }
        }

        /// <summary>
        /// Simple wrapper around the log4net Debug method.
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="messageFormat"></param>
        /// <param name="args"></param>
        public override void Debug(Exception exception, string message)
        {
            this.internalLogger.Debug(message, exception);
        }

        /// <summary>
        /// Simple wrapper around the log4net DebugFormat method.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="arguments"></param>
        public override void Debug(string message)
        {
            this.internalLogger.Debug(message);

        }

        /// <summary>
        /// Simple wrapper around the log4net IsInfoEnabled property.
        /// </summary>
        public override bool IsInfoEnabled
        {
            get
            {
                return this.internalLogger.IsInfoEnabled;
            }
        }

        /// <summary>
        /// Simple wrapper around the log4net InfoFormat method.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="arguments"></param>
        public override void Info(string message)
        {
            this.internalLogger.Info(message);
        }

        #endregion
    }

}
